home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / program / swags_z.zip / SORTING.SWG / 0036_Shell Sorting.pas < prev    next >
Pascal/Delphi Source File  |  1993-08-27  |  779b  |  41 lines

  1. {
  2. MATT HARGETT
  3.  
  4. : want to use the normal ole' bubble sorts and the like (on the order of N),
  5. : for the mere fact that it's just plain old slow!  Could anyone please post
  6. : some code, or pseudo-code of a sort that is on the order of NxLog N?  It wo
  7. }
  8.  
  9. Program ShellSort;
  10.  
  11. Var
  12.   A      : Array [1..1000] of Word;
  13.   I, J, N,
  14.   K, Tmp : Integer;
  15.  
  16. Begin
  17.   N := 1000;
  18.   For I := 1 to N Do
  19.   Begin
  20.     A[I] := Random(5000) + 1;
  21.     Write(A[I] : 6);
  22.   End;
  23.  
  24.   For K := 3 DownTo 1 Do
  25.     For I := 1 to N - 1 Do
  26.       For J := I + 1 to N Do
  27.         If A[J] < A[I]
  28.           then
  29.           Begin
  30.             Tmp  := A[J];
  31.             A[J] := A[I];
  32.             A[I] := Tmp;
  33.           End;
  34.  
  35.   Writeln;
  36.  
  37.   For I := 1 To N Do
  38.     Write(A[I] : 6);
  39. End.
  40.  
  41.